﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Collections.Generic;

public class Item : IItem, INotifyPropertyChanged
{
	static readonly PropertyChangedEventArgs _pcWidth = new PropertyChangedEventArgs("Width");
	int _width;

	public Item(int width)
	{
		Width = width;
	}

	#region IItem Members

	public int Width
	{
		get { return _width; }
		set
		{
			_width = value;
			OnWidthChanged();
		}
	}

	#endregion

	#region INotifyPropertyChanged Members

	public event PropertyChangedEventHandler PropertyChanged;

	#endregion

	protected void OnPropertyChanged(string name)
	{
		OnPropertyChanged(new PropertyChangedEventArgs(name));
	}

	protected void OnPropertyChanged(PropertyChangedEventArgs e)
	{
		if (PropertyChanged != null)
		{
			PropertyChanged(this, e);
		}
	}

	void OnWidthChanged()
	{
		OnPropertyChanged(_pcWidth);
	}

	public override string ToString()
	{
		return Width.ToString();
	}

	public override bool Equals(object obj)
	{
		return base.Equals(obj);
	}

	public bool Equals(Item other)
	{
		if (ReferenceEquals(null, other))
		{
			return false;
		}
		if (ReferenceEquals(this, other))
		{
			return true;
		}
		return other._width == _width;
	}

	public override int GetHashCode()
	{
		return _width;
	}
}